home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9000 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  53 lines

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Why doesn't this work?
  5. Date: 7 Mar 1996 16:46:31 GMT
  6. Organization: OpenVision
  7. Message-ID: <4hn3t7$rvt@spanky.pls.ov.com>
  8. References: <1996Mar4.161412.137442@forest>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article 137442@forest, ebromber@forest.drew.edu writes:
  13. >Does anyone know why this password program doesn't work properly? And if 
  14. >you do know the problem how can I fix it? It rejects every password including 
  15. >the real password. The program was compiled using a MS-DOS compiler.
  16. >Thanks in advance.
  17. >ebromber@drew.edu
  18. >
  19. >main();
  20. >{    char real[4];
  21. >    char pass[100];
  22. >    int count=0;
  23. >    int i, error;
  24. >    char c;
  25. >    real[0]='j';real[1]='e';real[2]='r';real[3]='k';
  26. >    printf("PASSWORD: ");
  27. >    fflush(stdout);
  28. >    while (c=getch() !='\n')
  29. >    {     count++;
  30. >        pass[count]=c;
  31.  
  32. Replace the two lines above with:
  33.                 pass[count++] = c;
  34. Otherwise, your first password character goes into pass[1].
  35.  
  36. >        putch('*');
  37. >    }
  38. >    if (count!=4) { printf("\nWRONG PASSWORD\n"); main();}
  39. >    error=0;
  40. >    for (i=0; i<4; i++)
  41. >        if (real[i]=pass[i]) error++;
  42.                            ^
  43. This is an assignment not a test.  You really want '!='.
  44.  
  45. >    if (error>0) {printf("\nWRONG PASSWORD\n"); main();}
  46. >}
  47. >
  48.  
  49. Lastly, why do you recursively call main on error?
  50.  
  51.             Fletcher.Glenn@ov.com
  52.  
  53.